package com.tanhua.app.controller;

import com.tanhua.app.service.SettingsService;
import com.tanhua.domain.db.Settings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    @GetMapping(value = "/users/settings", name = "读取通用设置")
    public ResponseEntity findSettingsVo() {
        return settingsService.findSettingsVo();
    }

    @PostMapping(value = "/users/questions", name = "设置陌生人问题")
    public ResponseEntity saveQuestion(@RequestBody Map param) {
        String content = (String) param.get("content");
        return settingsService.saveQuestion(content);
    }

    @PostMapping(value = "/users/notifications/setting", name = "设置通知")
    public ResponseEntity saveSettings(@RequestBody Settings settings) {

        return settingsService.saveSettings(settings);
    }

    @GetMapping(value = "/users/blacklist", name = "黑名单分页查询")
    public ResponseEntity findBlackListPage(@RequestParam(name = "page", defaultValue = "1") Integer pageNum,
                                            @RequestParam(name = "pagesize", defaultValue = "10") Integer pageSize) {
        return settingsService.findBlackListPage(pageNum,pageSize);
    }


    @DeleteMapping("/users/blacklist/{blackUserId}")
    public ResponseEntity deleteBlack(@PathVariable Long blackUserId){
        return settingsService.deleteBlack(blackUserId);
    }
}
